import { useUserStore } from '@/store/user';

export function useAuth() {
  const userStore = useUserStore();

  const isAuthenticated = () => userStore.isLoggedIn;

  const login = async () => {
    try {
      await userStore.wechatLogin();
      return true;
    } catch (error) {
      console.error('Login failed:', error);
      return false;
    }
  };

  const logout = () => {
    userStore.logout();
  };

  return {
    isAuthenticated,
    login,
    logout,
  };
}
